package com.ansion.preference;

import android.content.SharedPreferences;

import com.ansion.log.VLog;

public abstract class TurboBasePreference {

    private final String TAG = TurboBasePreference.class.getName();

    private ITurboBasePreference mDefaultPreferences;
    public static boolean MMKVEnable = false;

    public static boolean mmkvInited = false;
    public static String MMKVPath;

    protected TurboBasePreference(String name) {
        init(name, null);
    }

    protected TurboBasePreference(String name, String cryptKey) {
        init(name, cryptKey);
    }

    public void init(String name, String cryptKey) {
        VLog.i(TAG, "BotBasePreference initialize  ====> " + MMKVEnable);
        if (MMKVEnable) {
            mDefaultPreferences = new MMKVPreference(name, cryptKey);
        } else {
            mDefaultPreferences = new SharePreference(name);
        }
    }

    public boolean getMMKVEnable() {
        return MMKVEnable;
    }

    public boolean putFloat(String key, float value) {
        return mDefaultPreferences.putFloat(key, value);
    }

    public float getFloat(String key, float defValue) {
        return mDefaultPreferences.getFloat(key, defValue);
    }

    public boolean putInt(String key, int value) {
        return mDefaultPreferences.putInt(key, value);
    }

    public int getInt(String key, int defValue) {
        return mDefaultPreferences.getInt(key, defValue);
    }

    public boolean putLong(String key, long value) {
        return mDefaultPreferences.putLong(key, value);
    }

    public long getLong(String key, long defValue) {
        return mDefaultPreferences.getLong(key, defValue);
    }

    public boolean putString(String key, String value) {
        return mDefaultPreferences.putString(key, value);
    }

    public String getString(String key, String defValue) {
        return mDefaultPreferences.getString(key, defValue);
    }

    public boolean putBoolean(String key, boolean value) {
        return mDefaultPreferences.putBoolean(key, value);
    }

    public boolean getBoolean(String key, boolean defValue) {
        return mDefaultPreferences.getBoolean(key, defValue);
    }

    public boolean contains(String key) {
        return mDefaultPreferences.contains(key);
    }

    public void remove(String key) {
        mDefaultPreferences.remove(key);
    }

    public String[] getAllKeys() {
        return mDefaultPreferences.getAllKeys();
    }

    public SharedPreferences.Editor getEditor() {
        return mDefaultPreferences.getEditor();
    }

    public void clear() {
        mDefaultPreferences.clear();
    }

    public void logout() {}
}
